package com.huawei.utils;

import com.huawei.constants.CommonConstant;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.project.Project;

/**
 * 气泡消息工具类
 *
 * @since 2025-09-09
 */
public class NotificationUtil {
    /**
     * 生成10秒小时的提示气泡框
     */
    public static final NotificationGroup NORMAL_NOTIFICATION_GROUP = new NotificationGroup(
        CommonConstant.PLUGIN_NAME, NotificationDisplayType.BALLOON, true);

    /**
     * 气泡提示框：info
     *
     * @param project 项目
     * @param content 提示内容
     */
    public static void info(Project project, String content) {
        showNotification(project, content, NotificationType.INFORMATION);
    }

    /**
     * 气泡提示框：warn
     *
     * @param project 项目
     * @param content 提示内容
     */
    public static void warn(Project project, String content) {
        showNotification(project, content, NotificationType.WARNING);
    }

    /**
     * 气泡提示框：error
     *
     * @param project 项目
     * @param content 提示内容
     */
    public static void error(Project project, String content) {
        showNotification(project, content, NotificationType.ERROR);
    }

    private static void showNotification(Project project, String content, NotificationType notificationType) {
        Notification notification = NORMAL_NOTIFICATION_GROUP.createNotification(content, notificationType);
        notification.setTitle(CommonConstant.PLUGIN_NAME);
        if (project == null) {
            Notifications.Bus.notify(notification);
        } else {
            Notifications.Bus.notify(notification, project);
        }
    }
}
